package com.example.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.example.common.enums.ResultCodeEnum;
import com.example.common.exception.BusinessException;
import com.example.domain.CultureOrder;
import com.example.domain.CultureProductCollect;
import com.example.mapper.CultureOrderDao;
import com.example.service.CultureOrderService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (CultureOrder)表服务实现类
 *
 * @author lidongsheng
 * @since 2025-03-29 18:09:49
 */
@Service("cultureOrderService")
public class CultureOrderServiceImpl implements CultureOrderService {
    @Resource
    private CultureOrderDao cultureOrderDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CultureOrder queryById(Integer id) {
        return this.cultureOrderDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param cultureOrder 筛选条件
     * @param pageRequest  分页对象
     * @return 查询结果
     */
    @Override
    public Page<CultureOrder> queryByPage(CultureOrder cultureOrder, PageRequest pageRequest) {
        long total = this.cultureOrderDao.count(cultureOrder);
        return new PageImpl<>(this.cultureOrderDao.queryAllByLimit(cultureOrder, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param cultureOrder 实例对象
     * @return 实例对象
     */
    @Override
    public CultureOrder insert(CultureOrder cultureOrder) {
        this.cultureOrderDao.insert(cultureOrder);
        return cultureOrder;
    }

    /**
     * 修改数据
     *
     * @param cultureOrder 实例对象
     * @return 实例对象
     */
    @Override
    public CultureOrder update(CultureOrder cultureOrder) {
        this.cultureOrderDao.update(cultureOrder);
        return this.queryById(cultureOrder.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.cultureOrderDao.deleteById(id) > 0;
    }
}
